package com.xuhuan.demo.pattern.singleton.type2;

/**
 * @author huan.xu
 * @date 2021/10/2 23:08
 * @description 饿汉式(静态代码块)
 */
public class SingletonDemo2 {

  public static void main(String[] args) {
    System.out.println(Singleton.getInstence());
    System.out.println(Singleton.getInstence());
    System.out.println(Singleton.getInstence());
    System.out.println(Singleton.getInstence());
  }
}

class Singleton {

  private Singleton() {
  }

  private final static Singleton singleton;

  static {
    singleton = new Singleton();
  }

  public static Singleton getInstence() {
    return singleton;
  }
}
